﻿using AsmShaderConverter.AsmShader;
using AsmShaderConverter.HlslShader;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsmShaderConverter.AsmFunctions
{
    public class AsmFunctionFrc : IConvertToHlsl
    {
        readonly string originalLineOfCode;
        private Register destination;
        private Register source1;

        public Register GetDestinationRegister()
        {
            return this.destination;
        }
        public AsmFunctionFrc(string lineOfCode)
        {
            this.originalLineOfCode = lineOfCode;

            lineOfCode = lineOfCode.Replace(",", ""); // Remove commas.
            lineOfCode = lineOfCode.Trim(); // Remove dead space.
            var values = lineOfCode.Split(' '); // split

            switch (values.Length)
            {
                case 3:
                    this.destination = new Register(values[1], Swizzle.StandardXYZW);
                    this.source1 = new Register(values[2], destination.swizzle);
                    break;
                default:
                    throw new Exception("Function can´t be converted! " + lineOfCode);
            }

        }

        public string ToHLSL(AsmShaderFile asmShader)
        {
            return String.Format("{0} = frac({1});", this.destination.ToHLSL(asmShader), this.source1.ToHLSL(asmShader));
        }


        public string ToHLSLWitchComment(AsmShaderFile asmShader)
        {
            return this.ToHLSL(asmShader) + "//" + this.originalLineOfCode;
        }
    }
}
